//
//  MonthMenuViewTabviewCell.m
//  AroundTheWorld
//
//  Created by dllo on 16/5/26.
//  Copyright © 2016年 IfelseGo an. All rights reserved.
//

#import "MonthMenuViewTabviewCell.h"
#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height
#import "MonthMenulCollectionViewCell.h"

@implementation MonthMenuViewTabviewCell

//自定义初始化
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addView];
        self.myModelArray = [NSMutableArray array];
    }
    return self;
}
- (void)addView
{
    
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
   
    
    flowLayout.itemSize = CGSizeMake(110, 40);
    flowLayout.sectionInset = UIEdgeInsetsMake(20, 20, 20, 20);
    flowLayout.minimumLineSpacing = 20;
    UICollectionView *collectionV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) collectionViewLayout:flowLayout];
    
    collectionV.backgroundColor = [UIColor clearColor];
    collectionV.bounces = NO;
    collectionV.showsVerticalScrollIndicator = NO;
    [self.contentView addSubview:collectionV];
    
    //成为代理人
    collectionV.delegate = self;
    collectionV.dataSource = self;
    
    //注册
    [collectionV registerClass:[MonthMenulCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    self.myCollectionV = collectionV;
    
    



}
//cell数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.myModelArray.count;
}
//建cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    MonthMenulCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    FindTravellingMenuTimes_rangeModel *model = [self.myModelArray objectAtIndex:indexPath.row];
    cell.myLabel.text = model.descriptionMenu;
    return cell;
}
- (void)setMyModelArray:(NSMutableArray *)myModelArray
{
    _myModelArray = myModelArray;
    [self.myCollectionV reloadData];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.myCollectionV.frame = self.contentView.frame;
}

//点击触发方法

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    FindTravellingMenuTimes_rangeModel *model =[self.myModelArray objectAtIndex:indexPath.row];
    //通知
    [[NSNotificationCenter defaultCenter] postNotificationName:@"changeColor" object:model];

}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
